#include "bloomFX.h"

#include "FBO.h"

//Managers
#include "AbstractScene.h"
#include "shaderManager.h"
#include "shader.h"
#include "textureManager.h"
#include "texture2D.h"


BloomFX::BloomFX(const std::string& sName):AbstractEffect(sName)
{

}

BloomFX::~BloomFX()
{
}

void BloomFX::preProcess(unsigned int windowWidth, unsigned int windowHeight){


	ShaderManager & shaderManager = ShaderManager::getInstance();

	//threshold
	shaderManager.getShader("filters")->Activate();
	shaderManager.getShader("filters")->setUniformi("choix",3);
	
	AbstractScene::fboColorDepth->activate();
		AbstractScene::displayOnQuad(windowWidth,windowHeight);
	AbstractScene::fboColorDepth->desactivate();
	
	shaderManager.getShader("filters")->Desactivate();

	//vertical blur
	glActiveTexture(GL_TEXTURE1);
	AbstractScene::fboColorDepth->activateTexture();


	shaderManager.getShader("blur")->Activate();
	shaderManager.getShader("blur")->setUniformi("blurValue",25);
	shaderManager.getShader("blur")->setUniformi("windowWidth",windowWidth);
	shaderManager.getShader("blur")->setUniformi("windowHeight",windowHeight);
	shaderManager.getShader("blur")->setUniformi("choix",0);
	AbstractScene::fboBlurV->activate();
		AbstractScene::displayOnQuad(AbstractScene::fboBlurV->getWidth(), AbstractScene::fboBlurV->getHeight());
	AbstractScene::fboBlurV->desactivate();


	//horizontal blur
	glActiveTexture(GL_TEXTURE1);
	AbstractScene::fboBlurV->activateTexture();
			
	shaderManager.getShader("blur")->setUniformi("choix",1);
	AbstractScene::fboBlurH->activate();
			AbstractScene::displayOnQuad(AbstractScene::fboBlurH->getWidth(), AbstractScene::fboBlurH->getHeight());
	AbstractScene::fboBlurH->desactivate();
	shaderManager.getShader("blur")->Desactivate();



}

void BloomFX::process(unsigned int windowWidth, unsigned int windowHeight){


	ShaderManager & shaderManager = ShaderManager::getInstance();

	//add
	shaderManager.getShader("filters")->Activate();
	shaderManager.getShader("filters")->setUniformi("choix",4);

	glActiveTexture(GL_TEXTURE1);
	AbstractScene::fboBlurV->desactivateTexture();
	AbstractScene::fboBlurH->activateTexture();
	AbstractScene::displayOnQuad(windowWidth, windowHeight);

	glActiveTexture(GL_TEXTURE1);
	AbstractScene::fboBlurH->desactivateTexture();

}